package com.tevintao.marketingsystem.task;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.tevintao.marketingsystem.log.LogManager;
import com.tevintao.marketingsystem.services.TaskLogicService;
import com.tevintao.marketingsystem.services.ViewOperation;
import com.tevintao.marketingsystem.tool.ImageTool;
import com.tevintao.marketingsystem.xposted.WxTaskManger;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


/**
 * 接受别人发送的好友
 */
public class ReportIconTaskProcess extends SetTaskExtra {
    private static ReportIconTaskProcess ourInstance = new ReportIconTaskProcess();

    public static ReportIconTaskProcess getInstance() {
        return ourInstance;
    }

    private ReportIconTaskProcess() {
    }

    @SuppressWarnings("ResourceType")
    @Override
    public boolean processView(String contextName, View v) {
        if (WxUiViewConfig.MAIN_LAUNCH.equals(contextName)) {
            boolean me = WxUiViewConfig.inTab(v, WxUiViewConfig.TAB_ME);
            if (me) {
//                WxUiViewConfig.printViewGroup((ViewGroup) v);
                View nameView = v.findViewById(2131626780);
                if (nameView != null) {
                    View parent = (View) nameView.getParent().getParent();
                    if (null != parent) {
                        View image = parent.findViewById(2131625023);
                        if (null != image) {
                            Bitmap bitmap = ImageTool.convertViewToBitmap(image);
                            boolean saveIcon = ReportIcon.saveAccountIcon(bitmap);
                            if (saveIcon) {
                                v.getContext().sendBroadcast(new Intent(TaskLogicService.ACTION_KEY_REPORT_ACCOUNT_ICON));
                                taskError(v.getContext(), WxTaskManger.TASK_SATE_SUCCESS, "保存个人图像成功");
                            }
                        }
                    }
                }
            }
        }
        return false;
    }


}
